﻿using BlogDemo.Core.Entities;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlogDemo.Infrastructure.Database
{
    public class BlogContextSeed
    {
        public static async Task SeedAsync(BlogContext ctx,int retrytimes)
        {
            int retryAbilityTimes = retrytimes;
            try
            {
                if (!ctx.Post.Any())
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var newPost = new Post()
                        {
                            Author = "gainorloss",
                            Title = $"标题{i + 1}",
                            Body = $"内容{i + 1}",
                            LastModifyTime = DateTime.Now
                        };
                        await ctx.Post.AddAsync(newPost);
                        await ctx.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                retryAbilityTimes--;
            }
        }
    }
}
